package com.useeinfo.oa.modules.repair.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.DictInfo;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.base.entity.FacilityCat;
import com.useeinfo.oa.modules.base.entity.Organization;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/3 16:52
 * @Description: 设备故障分类
 */
@Entity
@Table(name = "trouble_cat")
public class TroubleCat extends SuperClassEntity<TroubleCat> {


    /**
     * 故障名称
     */
    private String troubleCatName;

    /**
    * 所属部门
    */
    @ManyToOne
    @JoinColumn(name = "organization_id")
    private Organization organization;

    private String organizationName;//部门快照

    /**
     * 工分
     */
    private Long points=0L;
    /**
     * 流水号
     */
    private String serial;

    /**
     * 报修专业
     */
    @ManyToOne
    @JoinColumn(name = "report_major")
    private DictInfo reportMajor;//废弃

    @ManyToOne
    @JoinColumn(name = "facility_cat")
    private FacilityCat facilityCat;


    private String major;//专业快照

    /**
     * 维修分类
     */
    @ManyToOne
    @JoinColumn(name = "report_classify")
    private DictInfo reportClassify;

    private String classify;//分类快照

    /**
     * * 关联企业
     * */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;


    public String getTroubleCatName() {
        return troubleCatName;
    }

    public void setTroubleCatName(String troubleCatName) {
        this.troubleCatName = troubleCatName;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public Long getPoints() {
        return points;
    }

    public void setPoints(Long points) {
        this.points = points;
    }

    public String getSerial() {
        return serial;
    }

    public void setSerial(String serial) {
        this.serial = serial;
    }

    public DictInfo getReportMajor() {
        return reportMajor;
    }

    public void setReportMajor(DictInfo reportMajor) {
        this.reportMajor = reportMajor;
    }

    public DictInfo getReportClassify() {
        return reportClassify;
    }

    public void setReportClassify(DictInfo reportClassify) {
        this.reportClassify = reportClassify;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getOrganizationName() {
        return organizationName;
    }

    public void setOrganizationName(String organizationName) {
        this.organizationName = organizationName;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public String getClassify() {
        return classify;
    }

    public void setClassify(String classify) {
        this.classify = classify;
    }

    public FacilityCat getFacilityCat() {
        return facilityCat;
    }

    public void setFacilityCat(FacilityCat facilityCat) {
        this.facilityCat = facilityCat;
    }

    @Override
    public JSONObject toJSONObject(){
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("troubleCat", StringConverters.null2String(getTroubleCatName()));
        jsonObject.put("organization", getOrganization() == null ? getOrganizationName() : StringConverters.null2String(getOrganization().getOrganizationName()));
        jsonObject.put("reportMajor", getReportMajor() == null ? getMajor() : StringConverters.null2String(getReportMajor().getPropertyName()));
        jsonObject.put("reportClassify", getReportClassify() == null ? getClassify() : StringConverters.null2String(getReportClassify().getPropertyName()));
        jsonObject.put("serial",StringConverters.null2String(getSerial()));
        jsonObject.put("points",StringConverters.null2Long(getPoints()));
        jsonObject.put("enterprise", getEnterprise() == null ? "" : StringConverters.null2String(getEnterprise().getEnterpriseName()));
        jsonObject.put("facilityCat", getFacilityCat() == null ? getMajor() : StringConverters.null2String(getFacilityCat().getCatName()));

        return jsonObject;
    }
}
